import unittest
import requests

class TestIhrmlogin(unittest.TestCase):
    def test01_login_success(self):
        url = "http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type":"application/json"}
        json_data = {"mobile":"13800000002","password":"123456"}
        resp = requests.post(url=url,headers=header,json=json_data)
        print("登陆成功", resp.json())

        self.assertEqual(200,resp.status_code)
        self.assertEqual(True,resp.json().get("success"))
        self.assertEqual(10000,resp.json().get("code"))
        self.assertIn("操作成功",resp.json().get("message"))

    def test02_pwd_err(self):
        url = "http://ihrm-java.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json_data = {"mobile": "13800000002", "password": "12345678"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登陆成功", resp.json())

        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json().get("success"))
        self.assertEqual(20001, resp.json().get("code"))
        self.assertIn("用户名或密码错误", resp.json().get("message"))